package com.dotflat.refund.service.impl;

import com.dotflat.fin.PO.RefundRecordItemPO;
import com.dotflat.refund.domain.RefundRecordItem;
import com.dotflat.refund.repository.RefundRecordItemRepository;
import com.dotflat.refund.service.RefundRecordItemService;
import com.dotflat.rest.service.impl.AreableObjectBaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
 * 订单信息service
 *
 * @author ：Ron
 * @date ：Created in 2020/10/30 13:06
 */
@Service
public class RefundRecordItemServiceImpl extends AreableObjectBaseServiceImpl<RefundRecordItem, RefundRecordItemRepository> implements RefundRecordItemService {

    @Override
    @Autowired
    public void setBaseRepository(RefundRecordItemRepository baseRepository) {
        super.setBaseRepository(baseRepository);
    }

    @Override
    @Transactional(rollbackOn = Exception.class)
    public List<RefundRecordItem> addAll(String areaId, String staffd, List<RefundRecordItemPO> pos, Consumer<RefundRecordItem> preAction) {
        List<RefundRecordItem> batch = new ArrayList<>();

        if (pos != null && pos.size() != 0){
            for (RefundRecordItemPO po : pos){
                RefundRecordItem item = add(areaId, staffd, po, preAction);
                batch.add(item);
            }
        }

        return batch;
    }
}
